package com.gxatek.cockpit.dvr.service;

import android.content.Context;
import android.hardware.SensorEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gxatek.cockpit.dvr.service.R;

import java.util.List;

public class SensorAdapter extends RecyclerView.Adapter<SensorAdapter.SensorViewHolder> {
    private List<SensorEvent> eventList  ;
    private Context mContext;
    LayoutInflater inflater;
    public SensorAdapter(Context context, List<SensorEvent> list){
        eventList = list ;
        mContext = context;
        inflater = LayoutInflater.from(context);
    }
    @NonNull
    @Override
    public SensorViewHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_sensor, parent,false);
        return new SensorViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull  SensorAdapter.SensorViewHolder holder, int position) {
        SensorEvent event = eventList.get(position);
        //Item event = eventList.get(position);
        holder.textView.setText("x: "+event.values[0]+" y:"+event.values[1]+" z:"+event.values[2]);
    }

    @Override
    public int getItemCount() {
        return eventList.size();
    }

    static class SensorViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        public SensorViewHolder(@NonNull   View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tvInfo);
        }
    }
}
